<head>
	<link rel="stylesheet" type="text/css" href="/members/profile_inner.css" />
	<script type="text/javascript" src="javascript/forum_home.js"></script>
</head>

<?php
error_reporting(0);
session_start();
error_reporting(1);

$site_root = "../";
require_once ($site_root . "common/PinSQL.obj");
$pinSQL = new PinSQL();
$pinSQL2 = new PinSQL();
$pinSQL3 = new PinSQL();



if (!$_SESSION['username']) { ?>
<table>
<tbody>
	<tr>
	
	<td>
		<div class="subhead">
			User Forum
		</div>
		<div class="simple">
			The forum is a place where members can meet and share their ideas about art and other topics.
		</div>
	</td>
	
	<td><img src="/img/separator.gif" /></td>
				
	<td width="100">
		<span class="subhead_purple">Log in:</span>
	</td>
		
	<td>
		<form name="login" method="post" action="/checkLogin.php">
		<?php if ($_GET['event'] == "badlogin") {
			?>
		<span class="redtext">Incorrect login information, please try again.</span>
		<?php } ?>
			<table><tr>
			<td>Username</td> <td><input name="username" class="loginform_p" type="text" size="25" /></td></tr>
			<tr><td>Password</td> <td><input name="password" class="loginform_p" type="password" size="25" /></td></tr>
			<tr><td></td><td><input class="loginform_p_button" type="submit" value="Login" /></td></tr></table>
			<div class="horizontal_separation"></div>
			<img src="/img/arrow_green.gif"><a href="/frame.php?page=signup.php">Don't have an account? Sign up!</a>
		</form>
	</td>
	
	</tr>
</tbody>
</table>
<?php } else {	// if logged in
?>

<table>
<tr>
<td style="width: 260px;">
<div class="jump_to">
Jump to thread... 
<select id="select_thread"><?php
$pinSQL->Query("SELECT * FROM forum_ids ORDER BY forum_id");
while ($row = $pinSQL->FetchNextRow())
{
	?><option value="forum<?php echo $row['forum_id']; ?>" style="font-weight: bold;"><?php echo $row['forum_name']; ?></option><?php
	$pinSQL2->Query("SELECT * FROM forum_thread_ids WHERE forum_id=" . $row['forum_id'] . " ORDER BY thread_id DESC");
	
	while ($thread = $pinSQL2->FetchNextRow())
	{
		?><option value="thread<?php echo $thread['thread_id']; ?>" style="font-style: italic;"><?php echo $thread['thread_name']; ?></option><?php
	}
}?>
</select><br /><div class="horizontal_separation"></div>
<input type="button" id="select_thread_submit" value="Go!" />
</div>
</td>
<td><div class="forum_search">
Search: <input type="text" id="forum_search" />
<br />
<div id="search_results" style="display: none;"></div>
</div>
</td>
</tr></table>


<?php
}?>
<div class="horizontal_separation"></div>
<div class="horizontal_separation"></div>
<div id="forums">

<table cellspacing="2">
	<tr align="center">
		<td width="340"></td>
		
		<td width="96">Last<img src="img/downarrow_orange.png" /></td>
		<td width="64">Threads<img src="img/downarrow_blue.png" /></td>
		<td width="64">Posts<img src="img/downarrow_green.png" /></td>
	</tr>

<?php

	

	$pinSQL->Query("SELECT * FROM forum_ids");
	
	while ( $row = $pinSQL->FetchNextRow() )
	{
?>

	<tr height="80">
		<td class="forum_banner" id="banner<?php echo $row['forum_id'] ?>"  onmouseover="highlightForumBanner(<?php echo $row['forum_id'] ?>);" onmouseout="highlightForumBanner(<?php echo $row['forum_id'] ?>);" onclick="showThreads(<?php echo $row['forum_id']?>);">
		
			<table><tr><td width="60">
				<img src="img/forum_icon.png" />
			</td><td>
				<div class="forum_title"><?php echo $row['forum_name']; ?></div>
				<?php echo $row['forum_description']; ?>
				</div>
			</td></tr></table>


		</td>
		<td class="forum_banner" id="last<?php echo $row['forum_id'] ?>" align="center" onmouseover="highlightForumBanner(<?php echo $row['forum_id'] ?>);" onmouseout="highlightForumBanner(<?php echo $row['forum_id'] ?>);" onclick="showThreads(<?php echo $row['forum_id']?>);">last user</td>
		<td class="forum_banner" id="threads<?php echo $row['forum_id'] ?>" align="center" onmouseover="highlightForumBanner(<?php echo $row['forum_id'] ?>);" onmouseout="highlightForumBanner(<?php echo $row['forum_id'] ?>);" onclick="showThreads(<?php echo $row['forum_id']?>);"><?php
		
		$pinSQL2->Query("SELECT * FROM forum_thread_ids WHERE forum_id=" . $row['forum_id']);
		echo $pinSQL2->GetNumRows();
		
		?></td>
		<td class="forum_banner" id="posts<?php echo $row['forum_id'] ?>" align="center" onmouseover="highlightForumBanner(<?php echo $row['forum_id'] ?>);" onmouseout="highlightForumBanner(<?php echo $row['forum_id'] ?>);" onclick="showThreads(<?php echo $row['forum_id']?>);"><?php
		
		$pinSQL2->Query("SELECT * FROM forum_posts WHERE forum_id=" . $row['forum_id']);
		echo $pinSQL2->GetNumRows();
		
		?></td>
	</tr>
	<tr><td>
		<div class="horizontal_separation">&nbsp;</div>	
	</td></tr>
	
	<tr>
	<td colspan="4">
		<table class="thread" cellspacing="2" border="0" cellpadding="0" id="threadList<?php echo $row['forum_id']; ?>" style="display: none;">
			<tr>
				<td class="threadHeaderName">Thread Name</td>
				<td class="threadHeaderLast">Last Post</td>
				<td class="threadHeaderPosts">Posts</td>
			</tr>			
			<?php
				$pinSQL2->Query("SELECT * FROM forum_thread_ids WHERE forum_id=" . $row['forum_id'] . " ORDER BY thread_id DESC");
				
				while ($thread = $pinSQL2->FetchNextRow())
				{
					?>
						<tr>
							<td colspan="3">
							<div style="background: rgb(22, 26, 71);" id="thread<?php echo $thread['thread_id']; ?>" onmouseover="highlightThread(<?php echo $thread['thread_id']; ?>);" onmouseout="highlightThread(<?php echo $thread['thread_id']; ?>);" onclick="clickThread(<?php echo $thread['thread_id']; ?>);">
							<table cellspacing="0" border="0" cellpadding="0">
										<tr class="threadName">
											<td style="width: 300px; padding: 2px;"><?php echo $thread['thread_name']; ?></td>
											<td style="width: 120px; padding: 2px; text-align: center;">&nbsp;</td>
											<td style="width: 60px; padding: 2px;text-align: center;">
												<?php $pinSQL3->Query("SELECT * FROM forum_posts WHERE forum_id=" . $row['forum_id'] . " AND thread_id=" . $thread['thread_id'] . " ORDER BY date");
												echo $pinSQL3->GetNumRows();
												?>																						
											</td>
										</tr>
										<tr>
											<td class="smallThreadText" style="padding: 2px;">Started by <?php echo $pinSQL3->GetUsername($thread['thread_creator']); ?></td>
											<td>&nbsp;</td>
											<td>&nbsp;</td>			
										</tr>
							</table>	
							</div>		
							</td>
							</tr>	
					<?php
				}
			?>		
		</table>
	
	</td>
	</tr>
	
	<tr><td>
		<div class="horizontal_separation">&nbsp;</div>
	</td></tr>

<?php
	}

?>
	
</table>
</div style="display: hidden;">
<div id="posts" style="display: none;">
<form name="thread" id="thread" method="post" action="sendThreadData.php">
<input type="hidden" id="threadId" name="threadId" value="" />
</form>
</div>
